#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) Huoty, All rights reserved
# Author: Huoty <sudohuoty@gmail.com>
# CreateTime: 2018-12-18 23:58:38

import time
import threading


v = 0
lock = threading.Lock()


def job1():
    global v
    print("acquire lock in job1:", lock.acquire())
    for _ in range(10):
        v += 1
        print('job1', v)
        time.sleep(0.5)
    lock.release()


def job2():
    lock.release()
    global v
    # print("acquire lock in job2:", lock.acquire(timeout=1))
    print("acquire lock in job2:", lock.acquire())
    for _ in range(10):
        v += 10
        print('job2', v)
        time.sleep(0.5)
    lock.release()


if __name__== '__main__':
    t1 = threading.Thread(target=job1)
    t2 = threading.Thread(target=job2)
    t1.start()
    t2.start()
    t1.join()
    t2.join()
